<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Cache" content="no-cache">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link href="/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
<link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
<link href="/css/plugins/bootstrap-table/bootstrap-table.min.css"
	rel="stylesheet">
<link href="/css/animate.min.css" rel="stylesheet">
<link href="/css/style.min.css?v=4.0.0" rel="stylesheet">
<!-- 搜索样式CSS 和 日期控件Start  -->
<link href="/common/css/searchStyle.css" rel="stylesheet">
<link href="/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
<link href="/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
<!-- 搜索样式CSS 和 日期控件End -->
<!-- 下拉 -->
<link href="/css/plugins/chosen/chosen.css" rel="stylesheet">
<link href="/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
<link href="/common/css/warningrule/warningruleindex.css" rel="stylesheet">
<link href="/common/css/clockpicker.css" rel="stylesheet">

</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<!-- Panel Other -->
		<div class="ibox float-e-margins" style="background-color: #fff">
			<form id="warningConfigForm">
				<div id="myTabContent" class="tab-content">
				<div style="width: 300px;box-sizing:content-box; padding-top: 45px;margin-left:460px;">
					<div class="button_top">
						<button id="submit" type="button" class="btn btn-w-m btn-primary">修改</button>
					</div>
					<div class="button_top">
						<button id="addWarningConfig" type="button"
							class="btn btn-w-m btn-success">新增预警规则</button>
					</div>
				</div>
					<!-- 配置信息Start -->
					<div class="tab-pane fade in active" id="relationTab">
						<div class="example-wrap" style="padding-bottom: 15px;">
							<div class="btn-group hidden-xs"
								role="group" style="margin-left: 2%">
								<div class="business_list" style="position: relative;">
									<label class="one" style="margin-right: 15px">项目名称</label>
									<select class="chosen-select" tabindex="8" name="projectId" id="projectName" style="width: 120px;">
									</select>
									<!-- 存ID -->
									<input type="hidden" id="arrayId">
									<!-- 存attr -->
									<input type="hidden" id="attrId">
								</div>
								<div class="business_list">
									<label class="one">配置名称</label><label class="tow">
									<input name="name" id="configName" placeholder="请输入配置名称"/></label>
								</div>
							</div>
							<table id="warningTable">
								<tr>
									<th>预警类型</th>
									<th>键</th>
									<th>值</th>
									<th>范围值</th>
									<th>预警时间间隔</th>
									<th>预警次数</th>
									<th>预警开始时间</th>
									<th>预警结束时间</th>
									<th>预警联系人员</th>
									<th>标题</th>
									<th>备注</th>
									<th>操作</th>
								</tr>
							</table>
							
						</div>

					</div>
					<!-- 配置信息End -->
					<H1 align="center">预警人员列表</H1>
					<table id="warningEmplTable" data-unique-id="id"  style="margin-bottom: 60px !important;">
					</table>
				</div>
			</form>
		</div>
	</div>
	<!-- End Panel Other -->

	<script src="/js/jquery.min.js?v=2.1.4"></script>
	<script src="/js/bootstrap.min.js?v=3.3.5"></script>
	<script src="/js/content.min.js?v=1.0.0"></script>
	<script src="/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
	<script src="/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
	<script
		src="/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
	<script src="/common/petecat.js"></script>
	<script src="/common/bootstrap-table.js"></script>
	<script src="/common/form.js"></script>
	<script src="/js/plugins/layer-pc/layer.js"></script>
	<script src="/js/jquery.cookie.js"></script>
	<script src="/common/bootstrap-table-treetable.js"></script>
	<!-- HTML之间的传值 -->
	<script src="/js/jquery.params.js"></script>
	<!-- 组件通用 -->
	<script src="/common/frame.js"></script>
	<!-- 下拉 -->
	<script src="/js/plugins/chosen/chosen.jquery.js"></script>
	<!-- 日期控件专用Start -->
	<script src="/js/jquery.cookie.js"></script>
	<!-- 日期控件专用End -->
	<script src="/js/plugins/datapicker/bootstrap-datepicker.js"></script>
	<script src="/common/clockpicker.js" ></script>
	<script type="text/javascript">
		var configDtoArray = new Array();
		//key:当前行attr数据  row:人员数组
		var parentEmplRowArray = new Array();
		//删除预警人员ID数组
		var delEmplArray = new Array();
		//删除规则行ID数组
		var delRuleArray = new Array();
		//预警类型加载下拉数据
		var warning_type_data = JSON.parse('[{"value":"服务器信息","key":"0"},{"value":"硬件","key":"1"},{"value":"软件","key":"2"},{"value":"应用","key":"3"},{"value":"服务器状态","key":"4"},{"value":"其他","key":"5"},{"value":"串口","key":"6"}]');
		var value_range = JSON.parse('[{"value":"相等","key":"0"},{"value":"大于","key":"1"},{"value":"小于","key":"-1"}]');
		$(function() {
			//获取ConfigId修改
			var configId = GetQueryString("configId");
			var req ={};
			req['reqJSON'] = {
				type:'get',
				url : BASE_URL+'/base/warningconfig/queryWarningConfig?configId='+configId
			}
			req['useToken'] = true;
			req['successFn'] = function(respData){
				configDtoArray = respData.data;
				//加载项目下拉内容
				initProjectSel();
				//将数据封装到页面中
				updHtmlData();
                
            };
            ajaxRequest(req);
            var table;
            var rows;
			//添加预警规则
			var rule_type = JSON.parse('[{"value":"有权限","key":"1"},{"value":"无权限","key":"0"}]');
			$("#addWarningConfig").click(function() {
				    table =document.getElementById("warningTable");
				    //-去<tr><th></th></tr>
				    rows = (table.rows.length-1);
					$("#warningTable").append(tableTrHtml(rows));
					//加载预警类型下拉
					var newItem = {};
					newItem['data'] = warning_type_data;
					newItem['id'] = 'transactionType'+rows;
					newItem['successFn'] = function(meItem){
						meItem.next().find('input').css("width","100px");
					};
					initSelectData(newItem);
					

					//加载value范围下拉
					var valueItem = {};
					valueItem['data'] = value_range;
					valueItem['id'] = 'valueRange'+rows;
					valueItem['successFn'] = function(meItem){
						meItem.next().find('input').css("width","100px");
					};
					initSelectData(valueItem);
					//初始化日期
					initTime();
			});
			//-----------------------------------------------------------
			//加载预警人员
			var outTable = {};
			outTable['id'] = 'warningEmplTable';
			outTable['columns'] = [
					{
			    	 field:'name',
			         title:'联系人名称'
				    },{
			    	 field:'sms',
			         title:'SMS'
				    },{
			    	 field:'email',
			         title:'联系人邮箱'
			    	},{
			    	 field:'smsRule',
			         title:'SMS权限',
			         formatter:function(value,row,index){
			        	 return '<div class="smsType">'
						  + '<select class="chosen-select" disabled="disabled" id="smsRule'+index+'" name="smsRule"  tabindex="8" style="width: 100px;">'
						  + '</select></div>';
			         }
				    },{
			    	 field:'emailRule',
			         title:'邮箱权限',
			         formatter:function(value,row,index){
			        	 return '<div class="emailType">'
							   +'<select class="chosen-select" disabled="disabled" id="emailRule'+index+'" name="emailRule"  tabindex="8" style="width: 100px;">'
							   +'</select></div>';
			         }
				    },{
						field : "opt",
						title : "操作",
						formatter : function() {
							return '<a class="update" href="javascript:void(0)" title="修改">修改</a>&nbsp;&nbsp;&nbsp;<a class="confim" href="javascript:void(0)" title="确定">确定</a>&nbsp;&nbsp;&nbsp;<a class="del" href="javascript:void(0)" title="删除">删除</a>';
						},
						events : {
							'click .del' : function() {
								var tr = $(this).parent().parent("tr");
								var uuId = $(this).parent().parent("tr").attr("data-uniqueid");
								$("#warningEmplTable").bootstrapTable('removeByUniqueId',uuId);
								tr.remove();
								//替换name
								var attr = $("#attrId").val();
								var emplAttr = $("[emplAttr='"+attr+"']");
								var emplName = emplAttr.val();
								var name =tr.children("td:first-child").text()+",";
								emplAttr.val(emplName.replace(name,"")); 
								//替换ID
								var emplId = emplAttr.next();
								var emplVal = emplId.val();
								var id = uuId+",";
								emplId.val(emplVal.replace(id,""));
								//删除移除parentEmplRowArray
								removeArrToArr(parentEmplRowArray,attr,uuId);
								//获取attrEmpl索引
								$("#emplId"+attr.substring(4)).click();
							},
							'click .update' : function(e, value, row, index) {
								var tr = $(this).parent().parent("tr");
								var smsRule = tr.find("[name='smsRule']");
								var emailRule = tr.find("[name='emailRule']");
								//解除禁用
								smsRule.attr("disabled",false);
								emailRule.attr("disabled",false);
								//更新样式
								smsRule.trigger("chosen:updated");
								emailRule.trigger("chosen:updated");
							},
							'click .confim' : function() {
								var tr = $(this).parent().parent("tr");
								var smsRule = tr.find("[name='smsRule']");
								var emailRule = tr.find("[name='emailRule']");
								//开启禁用
								smsRule.attr("disabled",true);
								emailRule.attr("disabled",true);
								//更新样式
								smsRule.trigger("chosen:updated");
								emailRule.trigger("chosen:updated");
								var attrKey = $("#attrId").val();
								var rowKey = $(this).parent().parent("tr").attr("data-uniqueid");
								$.each(parentEmplRowArray,function(index,items){
									 if(items['emplAttr'] == attrKey){ 
							            var emplRowArray = items['emplRowArray'];//key所对应的value  
							            $.each(emplRowArray,function(ind,item){
											if(item['rowKey'] == rowKey){
												var rowVal = item['rowVal'];
												rowVal['smsRule'] = smsRule.val();
												rowVal['emailRule'] = emailRule.val();
											}						            	
							            });
								    }  
									
								})
							}
						}
					}];
			initTable(outTable);
			//-----------------------------------------------------------
			
			//提交表单---》修改预警信息
			$("#submit").click(function(){
				
				var configName = $("#configName").val();
				var projectId = $("#projectName").val();
				if(configName == ""){
					layer.alert("请输入配置名称",{title:"内容不能为空",icon:3});
					return;
				}
				var warningNum = $(".warningNum");
				if(warningNum.length == 0){
					layer.alert("至少添加一条预警规则",{title:"内容不能为空",icon:3});
					return;
				}
				var form = $("#warningConfigForm");
				var data = serializeForm(form);
				var sendData ={},ruleList={};
				var id = data['id'];
				var type = data['type'];
				var keys = data['keys'];
				var value = data['value'];
				var valueRange = data['valueRange'];
				//间隔时间
				var rangeMinute = data['rangeMinute'];
				//间隔次数
				var rangeCount = data['rangeCount'];
				//预警开始时间 
				var rangeStartTime = data['rangeStartTime'];
				//预警结束时间 
				var rangeEndTime = data['rangeEndTime'];
				//预警人员姓名
				var emplName = data['emplName'];
				//预警标题
				var title = data['title'];
				//预警备注
				var remark = data['remark'];
				//预警规则
				var warningRuleList =[];
				var warningRule = {};
				//预警人员
				var emplInfoList = [];
				var emplInfo = {};
				var flag = false;
				var message;
				if(typeof type == "string"){
					if(keys == ""){
						message="键不能为空!";
						flag = true;
					}else if(value == ""){
						message="值不能为空!";
						flag = true;
					}else if(rangeMinute == "" || rangeMinute < 0){
						message="预警时间间隔信息有误";
						flag = true;
					}else if(rangeCount == "" || rangeCount < 0){
						message="预警次数信息有误";
						flag = true;
					}else if(!isTime(rangeStartTime)){
						message="规则开始时间有误";
						flag = true;
					}else if(!isTime(rangeEndTime)){
						message="规则结束时间有误";
						flag = true;
					}else if(emplName == ""){
						message="请选择对应的预警人员";
						flag = true;
					}else if(remark == ""){
						message="规则备注不能为空";
						flag = true;
					}
					if(flag){
						layer.alert(message,{icon:2});
						return;
					}
					warningRule['id'] = id;
				 	warningRule['type'] = type;
					warningRule['keys'] = keys;
					warningRule['value'] = value;
					warningRule['valueRange'] = valueRange;
					warningRule['rangeMinute'] = rangeMinute;
					warningRule['rangeCount'] = rangeCount;
					warningRule['rangeStartTime'] = rangeStartTime;
					warningRule['rangeEndTime'] = rangeEndTime;
					warningRule['title'] = title;
					warningRule['remark'] = remark;
					for(var k = 0;k<parentEmplRowArray.length;k++){
						for(var i = 0;i<parentEmplRowArray[k].emplRowArray.length;i++){
							info = parentEmplRowArray[k].emplRowArray[i];
							//预警人员
							emplInfo = {};
							emplInfo['userId'] = info['rowKey'];
							emplInfo['isEmail'] = info.rowVal.emailRule;
							emplInfo['isSms'] = info.rowVal.smsRule;
							emplInfoList.push(emplInfo); 
						}
					}
					warningRule['warningEmplList'] = emplInfoList;
					warningRuleList.push(warningRule);
				}else{
					 $.each(type,function(index,item){
						 if(keys[index] == ""){
								layer.alert("键不能为空!",{icon:2});
								flag = true;
								return false;
							}else if(value[index] == ""){
								layer.alert("值不能为空!",{icon:2});
								flag = true;
								return false;
							}else if(rangeMinute[index] == "" || rangeMinute[index] < 0){
								layer.alert("预警时间间隔信息有误!",{icon:2});
								flag = true;
								return false;
							}else if(rangeCount[index] == "" || rangeCount[index] < 0){
								layer.alert("预警次数信息有误!",{icon:2});
								flag = true;
								return false;
							}else if(!isTime(rangeStartTime[index])){
								layer.alert("规则开始时间有误!",{icon:2});
								flag = true;
								return false;
							}else if(!isTime(rangeEndTime[index])){
								layer.alert("规则结束时间有误!",{icon:2});
								flag = true;
								return false;
							}else if(emplName[index] == ""){
								layer.alert("请选择对应的预警人员!",{icon:2});
								flag = true;
								return false;
							}else if(remark[index] == ""){
								layer.alert("规则备注不能为空!",{icon:2});
								flag = true;
								return false;
							}
						warningRule = {};
						emplInfoList = [];
	                 	warningRule['type'] = item;
						warningRule['id'] = id[index];
	    				warningRule['keys'] = keys[index];
	    				warningRule['value'] = value[index];
	    				warningRule['valueRange'] = valueRange[index];
	    				warningRule['rangeMinute'] = rangeMinute[index];
	    				warningRule['rangeCount'] = rangeCount[index];
	    				warningRule['rangeStartTime'] = rangeStartTime[index];
	    				warningRule['rangeEndTime'] = rangeEndTime[index];
	    				warningRule['title'] = title[index];
	    				warningRule['remark'] = remark[index];
							for(var i = 0;i<parentEmplRowArray[index].emplRowArray.length;i++){
								info = parentEmplRowArray[index].emplRowArray[i];
								//预警人员
								emplInfo = {};
								emplInfo['userId'] = info['rowKey'];
								emplInfo['isEmail'] = info.rowVal.emailRule;
								emplInfo['isSms'] = info.rowVal.smsRule;
								emplInfoList.push(emplInfo); 
							}
						warningRule['warningEmplList'] = emplInfoList;
	    				warningRuleList.push(warningRule);
	                });
					 if(flag){
							return;
					 }
				}
				var status = 0;
				layer.confirm('是否启用当前规则？启动后将禁止其他该项目下得其他规则!',{
		            btn : [ '是', '否' ]//按钮
		        },function(index) {
		            status = 1;
		            layer.close(index);
					sendData['id'] = configId;
					sendData['name'] = configName;
					sendData['projectId'] = projectId;
					sendData['status'] = status;
					sendData['warningRuleList'] = warningRuleList;
					sendData['delEmplDTO'] = delEmplArray;
					sendData['delRules'] = delRuleArray;
					var req = {};
	                req['reqJSON'] = {
	                    type : 'put',
	                    url : BASE_URL+'/base/warningconfig/updateWarningConfig',
	                    data : JSON.stringify(sendData)
	                };
	                req['useToken'] = true;
	                req['successFn'] = function(respData){
	                    layer.msg(respData.message, {icon: 6,time:2000},function(){
	                        if(respData.code == SUCCESS_CODE){
	                            window.location.reload();
	                        }
	                    });
	                };
	                ajaxRequest(req);
		        },function(){
	                sendData['id'] = configId;
					sendData['name'] = configName;
					sendData['projectId'] = projectId;
					sendData['warningRuleList'] = warningRuleList;
					sendData['delEmplDTO'] = delEmplArray;
					sendData['delRules'] = delRuleArray;
					var req = {};
	                req['reqJSON'] = {
	                    type : 'put',
	                    url : BASE_URL+'/base/warningconfig/updateWarningConfig',
	                    data : JSON.stringify(sendData)
	                };
	                req['useToken'] = true;
	                req['successFn'] = function(respData){
	                    layer.msg(respData.message, {icon: 6,time:2000},function(){
	                        if(respData.code == SUCCESS_CODE){
	                            window.location.reload();
	                        }
	                    });
	                };
	                ajaxRequest(req);
		        }); 
				
				
			});
			
			
			//删除
			$(document).on("click", ".warningDel", function() {
				$(this).parents("tr").remove();
				var emplInput = $(this).parent().parent("tr").find(".chooseEmpl");
				var emplAttr = emplInput.attr("emplAttr");
				var web = new Object(); 
				//ID传值
				removeArray(parentEmplRowArray,emplAttr,web);
				//存放要的删除RuleId
				delRuleArray.push(web.ruleId);
				if(parentEmplRowArray.length == 0){
					$("#warningEmplTable").bootstrapTable('removeAll');
				}
				//如果删除的是第一个的话 直接删除
				$(".updEmpl")[0].click();
			})
			
			//编辑预警人员
			$("#warningTable").on("click",".warningNum", function() {
				var emplInput = $(this).find(".chooseEmpl");
				var emplName = emplInput.val();
				var emplAttr = emplInput.attr("emplAttr");
				$("#warningEmplTable").bootstrapTable('removeAll');
				/* if(emplName == ""){
					layer.alert("请先选择预警人员",{icon: 1,title:'温馨提示'})
					return;
				} */
				var emplRowArray = isExistsByKey1(parentEmplRowArray,emplAttr);
				if(emplRowArray != null){
					for(var i = 0;i<emplRowArray.length;i++){
						$('#warningEmplTable').bootstrapTable('append', emplRowArray[i].rowVal);
					}
					//循环渲染下拉框
					
					$.each(parentEmplRowArray,function(index,items){
						if(items['emplAttr'] == emplAttr){
							var emplRowArray = items['emplRowArray'];
							$.each(emplRowArray,function(ind,item){
								//渲染是否有sms
								sms = $("#smsRule"+ind);
								sms.chosen();
								var it = {
										'item':sms,
										'data':rule_type,
										key:'key',
										value:'value'
									};
								selectAppend(it);
								sms.val(item['rowVal'].smsRule);
								sms.trigger("chosen:updated");
								//渲染是否有email
								email = $("#emailRule"+ind);
								var itt = {
										'item':email,
										'data':rule_type,
										key:'key',
										value:'value'
									};
								selectAppend(itt);
								email.val(item['rowVal'].emailRule);
								email.trigger("chosen:updated");
							});
						}
					});
				}
				//设置临时
				$("#attrId").val(emplAttr);
			})
			
			//选择联系人
			$(document).on('click','.chooseEmpl',function(){
				var emplInput = $(this).parent().parent("tr").find(".chooseEmpl");
				//判断点的是第几个
				var emplAttr = emplInput.attr("emplAttr");
				//目前显示的是第几个
				var attr = $("#attrId").val();
				var emplName = emplInput.val();
				$("#arrayId").val($(this).next().val());
				if(emplName == ""){
				 	$("#warningEmplTable").bootstrapTable('removeAll');
				}
				layer.open({
					title:'选择预警通知人员',
					type:2,
					content:'/base/warning/empl/index_update.html?emplAttr='+emplAttr,
					area:['1000px','80%'],	
					shade:0.8,
					success:function(layer, index){
					},
					end:function(){
						var $table = $("#warningEmplTable");
						var emplData = $table.bootstrapTable('getData');
						var smsId;
						var emailId;
						$.each(emplData,function(index,item){
							smsId = $('#smsRule'+index);
							var itt = {
									'item':smsId,
									'data':rule_type,
									key:'key',
									value:'value'
								};
							selectAppend(itt);
							smsId.val(item.smsRule);
							smsId.trigger("chosen:updated");
							//邮箱反选
							emailId = $('#emailRule'+index);
							var itts = {
									'item':emailId,
									'data':rule_type,
									key:'key',
									value:'value'
								};
							selectAppend(itts);
							emailId.val(item.emailRule);
							emailId.trigger("chosen:updated");
						});
						//获取attrEmpl索引
						$("#emplId"+parseInt(emplAttr.substring(4))).click();
					}
				});
			})
		});
		
		
		//预警时间必须是10的倍数
		$("#warningTable").on("blur",".rangeMinute",function() {
			var $now = $(this);
			var value = $now.val();
			if (value == null || value == '') {
				value = 30;
			}
			var num = parseInt(value);
			//求余数
			var yu = num % 10;
			//不=0 说明不是10的倍数
			if(yu != 0){
				num -= yu;
				$now.val(num);
				layer.msg("系统已经为您转换为10的倍数！",{icon:6});
			}
		});
		
		function updHtmlData(){
			//配置名称
			var configName = configDtoArray.name;
			$("#configName").val(configName);
			//拼接预警规则内容
			tableUpdTrHtml(configDtoArray.warningRuleList);
			//加载下拉
			var newItem = {};
			var valueItem = {};
			var typeName;
			var valueName;
			for(var i = 0;i<parentEmplRowArray.length;i++){
				newItem = {};
				newItem['data'] = warning_type_data;
				newItem['id'] = 'transactionType'+i;
				newItem['successFn'] = function(meItem){
					meItem.next().find('input').css("width","100px");
				};
				initSelectData(newItem);
				//设置配置类型
				typeName= $("#transactionType"+i);
				typeName.val(typeName.attr("attr"));
				typeName.trigger("chosen:updated");
				
				//下载范围值下拉
				valueItem = {};
				valueItem['data'] = value_range;
				valueItem['id'] = 'valueRange'+i;
				valueItem['successFn'] = function(meItem){
					meItem.next().find('input').css("width","100px");
				};
				initSelectData(valueItem);
				//设置配置类型
				valueName= $("#valueRange"+i);
				valueName.val(valueName.attr("attr"));
				valueName.trigger("chosen:updated");
			}
			//初始化时间
			initTime();
			//默认展示第一行的预警人员
			$("#emplId1").click();
		}
		
		
		//初始化时间
		function initTime() {
			$('.clockpicker').clockpicker();
		}
		
		//加载项目下拉内容
		function initProjectSel(){
			var req = {};
	        req['reqJSON'] = {
	            type : 'get',
	            url : BASE_URL+'/base/project/queryProjectSelect'
	        };
	        req['useToken'] = true;
	        req['successFn'] = function(respData){
	        	var items = {
	        			id : "projectName",
	        			data : respData.data,
	        			key : "id",
	        			value : "text"
	        		};
	        	selectAppend(items);
	        	//项目ID
				var projectId = configDtoArray.projectId;
				var projectName = $("#projectName");
				projectName.val(projectId);
				projectName.trigger("chosen:updated");
	        };
	        ajaxRequest(req);
		}
		 
		//通过Key判断数组
		function isExistsByKey1(array, obj){
		    for (var i = 0; i < array.length; i++){
		        if (array[i].emplAttr == obj)//如果要求数据类型也一致，这里可使用恒等号===
		            return array[i].emplRowArray;
		    }
		    return null;
		}
		
		//通过数组ID移除数组中的数组
		function removeArrToArr(array,attr,rowKey){
			var userId = "";
			var ruleId = "";
			$.each(array,function(index,item){
				if(item.emplAttr == attr){
					for(var i = 0;i<item.emplRowArray.length;i++){
						if(item.emplRowArray[i].rowKey == rowKey){
							//只有第一次在库里的数据才回记录，后台删除
							if(item.ruleId){
								userId = item.emplRowArray[i].rowKey;
								ruleId = item.ruleId;
								delEmplArray.push({"userId":userId,"ruleId":ruleId});
							}
							item.emplRowArray.splice(i,1);
							return;
						}
					}
				}
			});
		}
		
		//通过数组ID移除数组中的数组
		function removeArray(array,attr,obj){
			$.each(array,function(index,item){
				if(item.emplAttr == attr){
					obj.ruleId=item.ruleId;
					array.splice(index,1);
					return false;
				}
			});
		}
		
		//拼接TrHTML -- > Add 新增
		function tableTrHtml(selectCount){
			return '<tr class="warningNum">'
			+ '<td>'
			+ '<input type="hidden" name="id" value=""/>'
			+ '<div class="transactionType">'
			+ '<select class="chosen-select" name="type" tabindex="8" id="transactionType'+selectCount+'" style="width: 110px;">'
			+ '</select>'
			+ '</div>'
			+ '</td>'
			+ '<td >'
			+ '<input  type="text" class="shortCls" name="keys" placeholder="输入   Key" />'
			+ '</td>'
			+ '<td >'
			+ '<input  type="number" class="shortCls" name="value" placeholder="输入   Value " />'
			+ '</td >'
			+ '<td>'
			+ '<div class="valueRange">'
			+ '<select class="chosen-select" name="valueRange" tabindex="8" id="valueRange'+selectCount+'" style="width: 110px;">'
			+ '</select>'
			+ '</div>'
			+ '</td>'
			+ '<td >'
			+ '<input  type="number" class="rangeMinute shortCls" name="rangeMinute" placeholder="输入预警时间间隔 " />'
			+ '</td>'
			+ '<td >'
			+ '<input  type="number" class="shortCls" name="rangeCount" placeholder="输入预警次数" />'
			+ '</td>'
			+ '<td>'
			+'<div class="input-group clockpicker" data-autoclose="true" >'
			+'<input type="text"  name="rangeStartTime" class="form-control shortCls" value="00:00">'
			+'<span class="input-group-addon">'
			+'<span class="glyphicon glyphicon-time"></span>'
			+'</span>'
			+'</div>'
			+ '</td>'
			+ '<td>'
			+'<div class="input-group clockpicker" data-autoclose="true" >'
			+'<input type="text" class="form-control shortCls" name="rangeEndTime" value="23:59">'
			+'<span class="input-group-addon">'
			+'<span class="glyphicon glyphicon-time"></span>'
			+'</span>'
			+'</div>'
			+ '</td>'
			+ '<td>'
			+ '	<input type="text" class="chooseEmpl" name="emplName" emplAttr="empl'+(selectCount+1)+'" readonly="readonly" placeholder="选择预警联系人员" />'
			+ '	<input type="hidden" />'
			+ '</td>'
			+ '<td >'
			+ '<input  type="text" name="title" placeholder="标题" />'
			+ '</td >'
			+ '<td >'
			+ '<input  type="text" name="remark" placeholder="预警规则备注" />'
			+ '</td >'
			+ '<td>'
			+ '<a href="javascript:void(0)" class="updEmpl" id="emplId'+selectCount+'">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" class="warningDel">删除</a>'
			+ '</td></tr>';
		}
		
		//拼接TrHTML -- > Update 修改
		function tableUpdTrHtml(ruleList){
			//修改TR
			var htmlTr="";
			//预警人员信息
			var warningEmplList;
			//人员ID,Name
			var emplId="";
			var emplName="";
			var req = {};
			var data = {};
			var rowArray = [];
			var emplAttr = "";
			$.each(ruleList,function(index,item){
				emplId="";
				emplName="";
				rowArray = [];
				emplAttr = "empl"+(index+1);
				//获取人员ID,名称 多行row装进下方empl
				warningEmplList = item.warningEmplList;
				if(null != warningEmplList){
					$.each(warningEmplList,function(ind,ite){
						emplId += ite.userId+",";
						emplName += ite.userName+",";
						//通过userId Ajax 获取User预警人员信息
						req = {};
						data = {"emplAttr":emplAttr,"emplId":ite.userId,"sms":ite.isSms,"email":ite.isEmail};
						req['reqJSON'] = {
								type:'get',
								async: false,
								url:SSO_URL+"system/companyempl/queryCompanyEmplListByUserId",
								data:data
						}
						req['useToken'] = true;
						req['successFn'] = function(respData){
							rowArray.push({"rowKey":respData.data.id,"rowVal":respData.data});
			            };
			            ajaxRequest(req);
					})
				}
				parentEmplRowArray.push({"emplAttr":"empl"+(index+1),"ruleId":item.id,"emplRowArray":rowArray});
				htmlTr += '<tr class="warningNum">'
					+ '<input type="hidden" name="id" value="'+item.id+'"/>'
					+ '<td>'
					+ '<div class="transactionType">'
					+ '<select class="chosen-select" attr='+item.type+' name="type" tabindex="8" id="transactionType'+index+'" style="width: 110px;">'
					+ '</select>'
					+ '</div>'
					+ '</td>'
					+ '<td >'
					+ '<input type="text" class="shortCls" name="keys" value='+item.keys+' placeholder="输入   Key " />'
					+ '</td>'
					+ '<td >'
					+ '<input  type="number" class="shortCls" name="value" value='+item.value+' placeholder="输入   Value " />'
					+ '</td >'
					+ '<td>'
					+ '<div class="valueRange">'
					+ '<select class="chosen-select shortCls" attr='+item.valueRange+' name="valueRange" tabindex="8" id="valueRange'+index+'" style="width: 100px;">'
					+ '</select>'
					+ '</div>'
					+ '</td>'
					+ '<td >'
					+ '<input  type="number" class="rangeMinute shortCls" name="rangeMinute" value='+item.rangeMinute+' placeholder="输入预警时间间隔 " />'
					+ '</td>'
					+ '<td >'
					+ '<input  type="number" class="shortCls" name="rangeCount" value='+item.rangeCount+' placeholder="输入预警次数" />'
					+ '</td>'
					+ '<td>'
					+'<div class="input-group clockpicker" data-autoclose="true" >'
					+'<input type="text"  name="rangeStartTime" class="form-control shortCls" value="'+item.rangeStartTime+'">'
					+'<span class="input-group-addon">'
					+'<span class="glyphicon glyphicon-time"></span>'
					+'</span>'
					+'</div>'
					+ '</td>'
					+ '<td>'
					+'<div class="input-group clockpicker" data-autoclose="true" >'
					+'<input type="text" class="form-control shortCls" name="rangeEndTime" value="'+item.rangeEndTime+'">'
					+'<span class="input-group-addon">'
					+'<span class="glyphicon glyphicon-time"></span>'
					+'</span>'
					+'</div>'
					+ '</td>'
					+ '<td>'
					+ '	<input type="text" class="chooseEmpl"  name="emplName" emplAttr="empl'+(index+1)+'" readonly="readonly" value="'+emplName+'" placeholder="选择预警联系人员" />'
					+ '	<input type="hidden" value="'+emplId+'"/>'
					+ '</td>'
					+ '<td >'
					+ '<input  type="text" name="title" value="'+item.title+'" placeholder="标题" />'
					+ '</td >'
					+ '<td >'
					+ '<input  type="text" name="remark" value="'+item.remark+'" placeholder="预警规则备注" />'
					+ '</td >'
					+ '<td>'
					+ '<a href="javascript:void(0)" class="updEmpl" id="emplId'+(index+1)+'">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" class="warningDel">删除</a>'
					+ '</td></tr>';
			});
			$("#warningTable").append(htmlTr);
		}
		
	</script>

</body>
</html>